<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<% String name = null;
    Cookie[] cookies = request.getCookies();
    for (Cookie cookie : cookies) {
        if ("username".equals(cookie.getName())) {
            name = cookie.getValue();
        }
    }
%>
<%
    Class.forName("com.mysql.cj.jdbc.Driver");
    System.out.println("JDBC驱动加载成功！");
    String url = "jdbc:mysql://localhost:3306/users";
    String user = "root";
    String password1 = "lcw0909.";
    Connection connection = DriverManager.getConnection(url, user, password1);
    String password = null;
    String sql = "SELECT userPassword FROM novelusers WHERE userAccount = ?";
    PreparedStatement preparedStatement = connection.prepareStatement(sql);
    preparedStatement.setLong(1, Long.valueOf(name));
// 执行查询并获取结果集
    ResultSet resultSet = preparedStatement.executeQuery();
// 处理结果集
    if (resultSet.next()) {
            password = resultSet.getString("userPassword");
    }
%><%--
  Created by IntelliJ IDEA.
  User: 86177
  Date: 2024/10/14
  Time: 15:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>写作中心</title>
</head>
<body>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
      integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link href="<%=request.getContextPath()%>/css/writingLan.css" rel="stylesheet">
<header>
    <nav class="navbar navbar-expand-lg bg-body-tertiary">
        <div class="container-fluid">
            <a class="navbar-brand" href="#">挽梦言句</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse"
                    data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
                    aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav me-auto mb-2 mb-lg-0 position-absolute top-50 end-0 translate-middle-yposition-absolute top-50 end-0 translate-middle-y"
                    style="padding-right: 20px">
                    <li class="nav-item">
                        <form method="post" action="<%=request.getContextPath()%>/login" style="display:none">
                            <input type="text" name="username" value="<%=name%>" style="display:none">
                            <input type="password" name="password" value="<%=password%>" style="display:none">
                            <button id="return-button" style="display:none;" type="submit"></button>
                        </form>
                        <a class="nav-link" id="return-a" href="#" style="color: #99e6f8">回到我的主页</a>
                    </li>
                    <li class="nav-item ">
                        <a class="nav-link" href="#" id="linkToClick" style="color: #410580">发表文章</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
</header>
<main>
    <div class="container">
        <h1>写作栏</h1>
        <form action="<%=request.getContextPath()%>/public-article" method="post">
            <label for="writingArea">在这里写作：</label>
            <textarea id="writingArea" name="writingContent"></textarea>
            <input type="text" name="useraccount" value="<%=Long.valueOf(name)%>" style="display:none">
            <br>
            <input type="submit" id="buttonToSimulate" style="display: none;" value="提交">
        </form>
    </div>
</main>
</body>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-/mhDoLbDldZc3qpsJHpLogda//BVZbgYuw6kof4u2FrCedxOtgRZDTHgHUhOCVim"
        crossorigin="anonymous"></script>
<script>
    document.addEventListener('DOMContentLoaded', function () {
        var link = document.getElementById('linkToClick');
        var button = document.getElementById('buttonToSimulate');

        link.addEventListener('click', function (event) {
            // 阻止<a>标签的默认行为（即跳转）
            event.preventDefault();

            // 触发按钮的点击事件
            button.click();
        });
    });
    document.addEventListener('DOMContentLoaded', function () {
        var link = document.getElementById('return-a');
        var button = document.getElementById('return-button');

        link.addEventListener('click', function (event) {
            // 阻止<a>标签的默认行为（即跳转）
            event.preventDefault();

            // 触发按钮的点击事件
            button.click();
        });

    });
</script>
</script>
</html>
